package org.lex.elec.model.dao.conn;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import org.lex.elec.model.AppException;
import org.lex.elec.model.ErrorCode;

public class ElecConnectionFactory {
	private static final ElecConnectionFactory INSTANCE = new ElecConnectionFactory();

	public static ElecConnectionFactory instance() {
		return INSTANCE;
	}

	public Connection getConnection() throws AppException {
		String user = "electric";
		String password = "china";
		String url = "jdbc:mysql://localhost:3306/electric";
		Connection connection;
		try {
			connection = DriverManager.getConnection(url, user, password);
			return connection;
		} catch (SQLException e) {
			throw new AppException(ErrorCode.DB_READ_ERROR, "can't connect to db:" + url, e);
		}
	}

	private ElecConnectionFactory() {
	}
}
